import 'dart:convert';

import 'package:flutter/services.dart';
import 'package:flutter_module/map/models/ni_geopoint_model.dart';
import 'package:flutter_module/system/log_util.dart';

import 'ni_map_method_id.dart';

class NILineDispatcher {
  Future<List<NIGeoPoint>?> addDrawLinePoint(MethodChannel mapChannel) async {
    var result = await mapChannel
        .invokeMethod(NILineMethodId.kMapAddDrawLinePointMethod);
    LogUtil.instance.printf(result);
    List list = jsonDecode(result);
    List<NIGeoPoint> points = [];
    for (var element in list) {
      NIGeoPoint point = NIGeoPoint(
          latitude: element["latitude"], longitude: element["longitude"]);
      points.add(point);
    }
    return points;
  }

  Future cleanDrawLine(MethodChannel mapChannel) async {
    await mapChannel.invokeMethod(NILineMethodId.kMapCleanDrawLineMethod);
  }
}
